package com.example.lenovo.a203_yhy_ordering_3.model;

import com.example.lenovo.a203_yhy_ordering_3.beans.RegisterBean;
import com.example.lenovo.a203_yhy_ordering_3.listener.RegisterListener;
import com.example.lenovo.a203_yhy_ordering_3.service.RegisterService;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by lenovo on 2018/11/12.
 */

public class RegisterModel {

    private Retrofit retrofit;

    public RegisterModel(){
        retrofit = new Retrofit.Builder()
                .baseUrl("http://172.24.10.175:8080/foodService/")
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }

    public void getResultList(String username, String userpass,String mobilphone,
                             String address,String comment, final RegisterListener registerlistener){

        RegisterService registerService = retrofit.create(RegisterService.class);

        Call<RegisterBean> registerBeanCall = registerService.userRegister(username,userpass,mobilphone,address,comment);

        registerBeanCall.enqueue(new Callback<RegisterBean>() {
            @Override
            public void onResponse(Call<RegisterBean> call, Response<RegisterBean> response) {
                if(response!=null)
                    registerlistener.onResponse(response.body());
                else registerlistener.onFail("获取注册信息失败");
            }

            @Override
            public void onFailure(Call<RegisterBean> call, Throwable t) {
                registerlistener.onFail(t.toString());
            }
        });


    }

}
